package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Student;
import service.StudentService;
import service.serviceImpl.StudentServiceimpl;

/**
 * Servlet implementation class UpdateServlet
 */
@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
		 req.setCharacterEncoding("utf-8");
		 String sno=req.getParameter("sno");
		 String sname=req.getParameter("sname");
		 String sex=req.getParameter("sex");
	     String age=req.getParameter("age");
	     String major=req.getParameter("major");
	     String password=req.getParameter("password");
	     Student stu=new Student();
	     
	      
//	     System.out.println(sname); 
//	     System.out.println(age); 
//	     System.out.println(major); 
//	     System.out.println(password); 
	     stu.setSno(Integer.parseInt(sno));
	     stu.setSname(sname);
	     stu.setAge(Integer.parseInt(age));
	     stu.setMajor(major);
	     stu.setPassword(Integer.parseInt(password));
	     stu.setSex(sex);
	     StudentService ser = new StudentServiceimpl();
	     int stu1=0;
	      stu1=ser.updataStudent(stu);
	 
	 	req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
	
		req.removeAttribute("id");
		req.removeAttribute("flag");
		req.setAttribute("id", 2);
	     req.setAttribute("flag", stu1);
//	     System.out.println(stu);


	    	  req.getRequestDispatcher("admin.jsp").forward(req, resp);
	     
	}

}
